package org.lds.hotkey.console.remote;

import org.lds.hotkey.common.model.dto.ResultDTO;
import org.lds.hotkey.common.util.RestUtil;
import org.lds.hotkey.console.remote.model.request.AppInstanceRegisterRequest;
import org.lds.hotkey.console.remote.model.request.BatchCurrHotKeySaveRequest;
import org.lds.hotkey.console.remote.model.request.WorkerRegisterRequest;
import org.springframework.core.ParameterizedTypeReference;

public class ConsoleClient {
    private final String endpoint;

    public ConsoleClient(String endpoint) {
        this.endpoint = endpoint;
    }

    public ResultDTO<Long> registerAppInstance(AppInstanceRegisterRequest request) {
        String url = endpoint + "/api/remote/appinstance/register";
        return RestUtil.post(url, request, new ParameterizedTypeReference<ResultDTO<Long>>() {});
    }

    public ResultDTO<Boolean> saveCurrHotKey(BatchCurrHotKeySaveRequest request) {
        String url = endpoint + "/api/remote/currHotKey/save";
        return RestUtil.post(url, request, new ParameterizedTypeReference<ResultDTO<Boolean>>() {});
    }

    public ResultDTO<Long> registerWorker(WorkerRegisterRequest request) {
        String url = endpoint + "/api/remote/worker/register";
        return RestUtil.post(url, request, new ParameterizedTypeReference<ResultDTO<Long>>() {});
    }

}
